package com.bawei.module_goods.adapter

import android.view.LayoutInflater
import android.view.View
import android.view.ViewGroup
import android.widget.ImageView
import android.widget.TextView
import androidx.recyclerview.widget.RecyclerView
import com.bawei.module_goods.R
import com.bawei.module_goods.entity.Record
import com.bumptech.glide.Glide

class CommentAdapter(private val list: List<Record>) : RecyclerView.Adapter<CommentAdapter.VH>() {
    class VH(view: View) : RecyclerView.ViewHolder(view) {
        val ivAvatar: ImageView = view.findViewById(R.id.ivAvatar)
        val tvName: TextView = view.findViewById(R.id.tvName)
        val tvContent: TextView = view.findViewById(R.id.tvContent)
        val tvTime: TextView = view.findViewById(R.id.tvTime)
    }
    override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): VH {
        val view = LayoutInflater.from(parent.context).inflate(R.layout.item_comment, parent, false)
        return VH(view)
    }
    override fun getItemCount() = list.size
    override fun onBindViewHolder(holder: VH, position: Int) {
        val item = list[position]
        val avatarUrl = item.headImg?.toString().takeIf { !it.isNullOrBlank() }
        Glide.with(holder.ivAvatar.context)
            .load(avatarUrl)
            .placeholder(R.drawable.ic_default_avatar)
            .circleCrop()
            .into(holder.ivAvatar)
        holder.tvName.text = item.createName
        holder.tvContent.text = item.content
        holder.tvTime.text = item.createTime
    }
} 